﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Projektet.Model
{
    class Archer : CombatUnit
    {
        public int _attackRange = 18;

        public Archer(PlayerType playerType, Vector2 startPos, UnitStats unitstats) 
        {
            _width = 3;
            _height = 4;
            _attackInterval = unitstats.ArcherAttackSpeed;
            _health = unitstats.ArcherHealth;
            _moveSpeed = unitstats.ArcherMoveSpeed;
            _playerType = playerType;
            if(playerType == PlayerType.Npc)
            {
                _moveSpeed *= -1f;
            }
            
            _damage = unitstats.ArcherDamage;
            
            _unitPosition = new Vector2(startPos.X, startPos.Y);
        }

        public override bool IsInContact(Rectangle targerRect)
        {
            int result = _unitRect.X - targerRect.X;
            if (result < 0)
            {
                result *= -1;
            }

            if (result < _attackRange)
            {
                //Console.WriteLine("Nära!");
                _unitState = UnitState.Fighting;
                return true;
            }
            //if (_unitRect.Intersects(targerRect))
            //{
            //    //Console.WriteLine("Archer contact!");
            //    _unitState = UnitState.Fighting;
            //    return true;
            //}
            else
            {
                //_unitState = UnitState.Moving;
                return false;
            }
        }
        public override void TakeDamage(Combat.Attack attack)
        {
            //If-satser eller switch som avgör hur mycket damage som ska tas beroende på enhetstyp
            //Console.WriteLine(_health);
            switch(attack.AttackType)
            {
                case Combat.AttackType.Arrow:
                    _health -= attack.Power;
                    break;
                case Combat.AttackType.Pike:
                    _health -= (attack.Power / 2);
                    break;
                case Combat.AttackType.Sword:
                    _health -= (attack.Power * 1.5f);
                    break;
                case Combat.AttackType.Other:
                    _health -= attack.Power;
                    break;                    
            }            
        }
    }
}
